<template>
	<view>
		<u-row customStyle="margin-bottom: 80px">
			<u-col span="12">
				<view>
					<u-navbar
					    title="面试反馈"
						titleStyle="font-weight:bold"
					    :safeAreaInsetTop="true"
						:fixed='true'
						bgColor="#FFBE59"
						@leftClick="leftClick"
						@rightClick="rightClick"
					>
					    <view
					        class="u-nav-slot"
					        slot="left"
							
					    >
					        <u-icon
					            name="arrow-left"
					            size="20"
								color="black"
					        ></u-icon>
					    </view>
						<view
						    class="u-nav-slot"
						    slot="right"
						>
						    <span style="font-size: 15px;font-weight: bold;color:#3A3A3A">保存</span>
						</view>
					</u-navbar>
				</view>
			</u-col>
		</u-row>
		<u-row customStyle="margin-bottom: 0px">
			<u-col span="11" style="margin: 0 auto;">
				<view>
					<u-col span="11" style="margin: 0 auto;">
						<view style="border-bottom: 0.1px solid #E5E4E2;height: 48px;" @click="show=true">
							<p style="color: grey;font-size: 15px;">面试结果</p>
							<span style="font-size: 14px;font-weight: bold;">{{this.resultValue}}</span>
							<u-icon class="name-title-icon" name="arrow-right" color="#ADADAD" size="16" style="float: right;"></u-icon>
							<u-picker :show="show" :columns="columns" @confirm="resultConfirm" @cancel="resultCancel"></u-picker>
						</view>
					</u-col>
					<u-col span="11" style="margin: 0 auto;margin-top: 20px;">
						<view>
							<span style="margin-left: 3px;font-size: 15px;"><span style="color: grey;">面试总结</span></span>
							<u--textarea style="margin-top:4px;" v-model="value1" placeholder="请输入对本次面试的总结" height="200"></u--textarea>
						</view>
					</u-col>
				</view>
			</u-col>
		</u-row>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
					value1: '',
					interviewId:'',
					feedbacResource:{},
					i:'',
					id:'',
					show: false,
					columns: [
						['面试通过', '面试未通过']
					],
					resultValue:'',
					stu:{},
			};
		},
		created() {
			this.stu = uni.getStorageSync('stu');
			//通过面试预约编号查询反馈表
			this.$axios.get('/resource/feedbacResource/queryByInterviewId?interviewId='+this.interviewId).then((res)=>{
				if(res.data.success){
					this.i = 2;//修改
					this.value1 = res.data.result.resourceName;
					if(res.data.result.interviewResults==0){
						this.resultValue = "面试通过";
					}else{
						this.resultValue = "面试未通过";
					}
					this.id = res.data.result.id;
				}else{
					this.i = 1;//新增
				}
			})
		},
		methods:{
			resultConfirm(e) {
				this.resultValue = e.value[0];
				this.show = false;
			},
			resultCancel(){
				this.show = false;
			},
			//左侧点击返回上一页面
			leftClick(){
				uni.redirectTo({
					url: '/pages/service/employmentservice/employmenInterview/employmenInterview?interviewStuName='+this.stu.stuId,
				});
			},
			//右侧点击保存
			rightClick(){
				var flag = true;
				if(this.value1==""&&this.value1==undefined){
					flag = false;
				}
				if(this.resultValue==""&&this.resultValue==undefined){
					flag = false;
				}
				if(flag==true){
					if(this.resultValue=="面试通过"){
						this.feedbacResource.interviewResults = 0;
					}
					if(this.resultValue=="面试未通过"){
						this.feedbacResource.interviewResults = 1;
					}
					this.feedbacResource.resourceName = this.value1;//反馈内容
					this.feedbacResource.interviewId = this.interviewId;//面试预约编号
					if(this.i==1){//新增
						this.feedbacResource.stuId = this.stu.stuId;//学生编号
						this.$axios.post('/resource/feedbacResource/addResource',this.feedbacResource).then((res)=>{
							if(res.data.success){
								uni.redirectTo({
									url: '/pages/service/employmentservice/employmenInterview/employmenInterview?interviewStuName='+this.stu.stuId,
								});
							}else{
								uni.showToast({
									icon: 'error',
									position: 'bottom',
									title: '保存失败'
								});
							}
						});
					}else{//修改
						this.feedbacResource.id = this.id;
						this.$axios.post('/resource/feedbacResource/upResource',this.feedbacResource).then((res)=>{
							if(res.data.success){
								uni.redirectTo({
									url: '/pages/service/employmentservice/employmenInterview/employmenInterview?interviewStuName='+this.stu.stuId,
								});
							}else{
								uni.showToast({
									icon: 'error',
									position: 'bottom',
									title: '保存失败'
								});
							}
						});
					}
				}else{
					uni.showToast({
						icon: 'error',
						position: 'bottom',
						title: '反馈内容不能为空'
					});
					Window.eval(flag);
				}
			},
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			this.interviewId = option.interviewId;//面试预约编号
		}
	}
</script>

<style lang="less">

</style>
